import numpy as np
import cv2
dx = 8
dy = -16
REFERENCE_FACIAL_POINTS = [
    [30.29459953 - dx,   51.69630051 + dy],  # left eye
    [65.53179932 + dx,   51.50139999 + dy],  # right eye
    [48.02519989,        71.73660278 + dy + 5],  # nose
    [33.54930115 - dx/2, 92.3655014  + dy],   # left mouth
    [62.72990036 + dx/2, 92.20410156 + dy]   # right mouth
]

DEFAULT_CROP_SIZE = (96, 112)
tmp_5pts = np.array(REFERENCE_FACIAL_POINTS)
tmp_crop_size = np.array(DEFAULT_CROP_SIZE)

# 转换成方形
size_diff = max(tmp_crop_size) - tmp_crop_size
tmp_5pts += size_diff / 2
tmp_crop_size += size_diff


ref_pts = np.float32(tmp_5pts)
# 缩放因子

factor = 0.90
crop_size = 196

ref_pts = (ref_pts - 112 / 2) * factor + 112 / 2
ref_pts *= crop_size / 112.
print(ref_pts)
print(f"Point2f({ref_pts[0][0]},{ref_pts[0][1]}),   // left eye")
print(f"Point2f({ref_pts[1][0]},{ref_pts[1][1]}),   // right eye")
print(f"Point2f({ref_pts[2][0]},{ref_pts[2][1]}),   // nose")
print(f"Point2f({ref_pts[3][0]},{ref_pts[3][1]}),   // left mouth")
print(f"Point2f({ref_pts[4][0]},{ref_pts[4][1]}),   // right mouth")


# 创建一个空白图像
image = np.zeros((crop_size, crop_size, 3), dtype=np.uint8)

# 绘制关键点
for point in ref_pts:
    x, y = int(point[0]), int(point[1])
    cv2.circle(image, (x, y), 5, (0, 255, 0), -1)

# 显示图像
cv2.imshow('Facial Points', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
